package com.dream.libxrec.rec.audio;

import android.media.MediaCodec;
import android.media.MediaFormat;
import com.dream.libxrec.encode.audio.IAudioEncoder;
import com.dream.libxrec.encode.audio.IAudioEncoderListener;

import java.nio.ByteBuffer;

public class AACRecorder extends IAudioRec{

    private IAudioEncoder mAudioEncoder;
    private final IAudioEncoderListener mCb = new IAudioEncoderListener() {
        @Override
        public void onFormat(MediaFormat format) {}

        @Override
        public void onFrame(ByteBuffer buffer,
                            MediaCodec.BufferInfo info) {}

        @Override
        public void onFrame(byte[] buffer, int size, long pts) {}
    };

    @Override
    public void init(String path, IAudioEncoder encoder) {
        this.mAudioEncoder = encoder;
        encoder.addIEncoderListener(mCb);
        encoder.start();
    }

    @Override
    public void write(byte[] pcm, int size) {
        mAudioEncoder.encode(pcm,0,size);
    }

    @Override
    public void release() {
        mAudioEncoder.stop();
    }
}
